Skip to content

Conversation

@Sebastian-Larsson
Copy link
Collaborator

Previously, dequantizing a value with dequantize_value() in backends/arm/tosa_quant_utils.py could result in integer overflow when using numpy 2.1.3. The offending part of the formula is qx - qargs.zp. If the subtraction results in a value outside of the range of the dtype of qx the following warning is printed:

"RuntimeWarning: overflow encountered in scalar subtract"

With numpy 1.21.3 the dtype is implicitly convert to a dtype that can store the correct value. However, in numpy 2.1.3 there's no such conversion, leading the function to return an incorrect value.

Here's a concrete example:

import numpy as np

a = np.int8(127)
b = -128

print(a-b)

Numpy 1.21.3: a - b = 255
Numpy 2.1.3: a - b = -1

To remedy this, explicitly convert qx to int64.

Signed-off-by: Sebastian Larsson [email protected]

Previously, dequantizing a value with dequantize_value() in
backends/arm/tosa_quant_utils.py could result in integer overflow when
using numpy 2.1.3. The offending part of the formula is `qx - qargs.zp`.
If the subtraction results in a value outside of the range of the dtype
of `qx` the following warning is printed:

"RuntimeWarning: overflow encountered in scalar subtract"

With numpy 1.21.3 the dtype is implicitly convert to a dtype that can
store the correct value. However, in numpy 2.1.3 there's no such
conversion, leading the function to return an incorrect value.

Here's a concrete example:

```
import numpy as np

a = np.int8(127)
b = -128

print(a-b)

```

Numpy 1.21.3: a - b = 255
Numpy 2.1.3: a - b = -1

To remedy this, explicitly convert qx to int64.

Change-Id: Ie0e9e7745a424103ce650e2d58fe1a1a4cbd30e1
@pytorch-bot
Copy link

pytorch-bot bot commented Dec 11, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/7289

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit efb97d5 with merge base 3f7eb3b (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 11, 2024
@Sebastian-Larsson
Copy link
Collaborator Author

@pytorchbot label ciflow/trunk

@pytorch-bot
Copy link

pytorch-bot bot commented Dec 11, 2024

Can't add following labels to PR: ciflow/trunk. Please ping one of the reviewers for help.

@zingo zingo added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm ciflow/trunk labels Dec 11, 2024
@pytorch-bot
Copy link

pytorch-bot bot commented Dec 11, 2024

Please seek CI approval before scheduling CIFlow labels

@Sebastian-Larsson
Copy link
Collaborator Author

@pytorchbot label ciflow/trunk

@freddan80
Copy link
Collaborator

Pls rebase

@Sebastian-Larsson
Copy link
Collaborator Author

Rebase done. Failing CI test seems unrelated. Error:

examples/models/llama3_2_vision/text_decoder/test/
test_text_decoder.py::TextDecoderTest::test_llama3_2_text_decoder_aoti

@freddan80 freddan80 merged commit 80f1c1b into pytorch:main Dec 13, 2024
105 of 106 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm topic: not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants